package fr.neyb.framework.util;

import java.util.List;

public class CharSequences {
	private CharSequences() {
	}

	public static interface Formatter<T> {
		String format(T source);
	}
	
	public static interface Parser<T>{
		T parse(CharSequence source);
	}

	public static String concatenate(String Separator, List<String> strings) {
		StringBuilder sb = new StringBuilder();

		for (String s : strings) {
			sb.append(s + Separator);
		}

		return sb.delete(sb.length() - Separator.length(), sb.length())
				.toString();
	}

	public static <T> String concatenate(String Separator,
			Formatter<T> stringyfier, List<T> objects) {
		StringBuilder sb = new StringBuilder();

		for (T o : objects) {
			sb.append(stringyfier.format(o) + Separator);
		}

		return sb.delete(sb.length() - Separator.length(), sb.length())
				.toString();
	}

}
